package cn.mengfly.algorithm.collection.queue;

import cn.mengfly.algorithm.sort.SortUtil;

/**
 * @author Mengfly
 * @date 2021/6/2 22:21
 */
public class HeapMaxPriorityQueue<Key extends Comparable<? super Key>> implements MaxPriorityQueue<Key> {

    private final HeapPriorityHelper<Key> delegate;

    public HeapMaxPriorityQueue(int size) {
        delegate = new HeapPriorityHelper<>(size, SortUtil::less);
    }

    @Override
    public void insert(Key v) {
        delegate.insert(v);
    }

    @Override
    public Key max() {
        return delegate.priorityValue();
    }

    @Override
    public Key delMax() {
        return delegate.delPriorityValue();
    }

    @Override
    public boolean isEmpty() {
        return delegate.size() == 0;
    }

    @Override
    public int size() {
        return delegate.size();
    }
}
